package com.example.a10928.weifriend.ui.home.menu

import android.annotation.SuppressLint
import android.databinding.ViewDataBinding
import android.support.v7.widget.LinearLayoutManager
import com.example.a10928.weifriend.App.app
import com.example.a10928.weifriend.R
import com.example.a10928.weifriend.adapter.NoticeAllAdapter
import com.example.a10928.weifriend.databinding.FragmentTaskRecordBinding
import com.example.a10928.weifriend.ui.BaseActivity
import com.example.a10928.weifriend.ui.DatabindingBaseActivity
import com.example.a10928.weifriend.util.RxUtil
import com.example.a10928.weifriend.ui.MainActivity
import com.mylhyl.circledialog.CircleDialog



class NoticeActivity : DatabindingBaseActivity() {
    lateinit var mBinding: FragmentTaskRecordBinding
    override fun bindingInitData() {
    }

    override fun bindingInitView(viewDataBinding: ViewDataBinding?) {
        mBinding = viewDataBinding as FragmentTaskRecordBinding
        setTitleText(ThemeEnum.Back_Default,"公告历史")
        getAllNotce()


    }

    override fun bindingGetContentView(): Int {
        return R.layout.fragment_task_record
    }

    @SuppressLint("CheckResult")
    fun getAllNotce() {
        app().bpService.allDetatl
                .compose(RxUtil.io2mainLoad(this))
                .subscribe(
                        { r ->
                            var adapter = NoticeAllAdapter(R.layout.item_all_notice, r.data!!)
                            mBinding.taskRecordRv.adapter = adapter
                            mBinding.taskRecordRv.layoutManager = LinearLayoutManager(this)

                            adapter.setOnItemClickListener { adapter, view, position ->

                                CircleDialog.Builder()
                                        .setTitle("公告")
                                        .setText(r.data[position].notice_content+r.data[position].notice_content)
                                        .setPositive("确定", null)
                                        .show(supportFragmentManager)
                            }
                        }, { RxUtil::errorException }
                )
    }

}